package com.stormrage.edu.ctrl.exam;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.stormrage.edu.serv.adm.AdmAcctServ;
import com.stormrage.edu.serv.edu.EduMajorServ;
import com.stormrage.entity.adm.AdmRes;
import com.stormrage.entity.edu.rep.EduMajorRep;
import com.stormrage.entity.shiro.ShiroAcct;
import com.stormrage.shiro.bind.CurrentUser;
import com.stormragetech.core.ctrl.BaseCtrl;

/**
 * @Title: ExmMajorCtrl.java
 * @Package com.stormrage.edu.ctrl.exam
 * @Description: 考试 专业 Controller
 * @author www.stormragetech.com
 * @date 2016年4月24日
 * @version V1.0
 */
@Controller
@RequestMapping("/exam/major")
public class ExmMajorCtrl extends BaseCtrl {

	private static final Logger logger = LoggerFactory.getLogger(ExmMajorCtrl.class);

	@Value("#{constants['html.title']}")
	private String htmlTitle;

	@Autowired
	private AdmAcctServ admAcctServ;

	@Autowired
	private EduMajorServ eduMajorServ;

	@RequiresPermissions("exam:create")
	@RequestMapping(value = "/list/{id}")
	public String list(@CurrentUser ShiroAcct curr, @PathVariable("id") Integer id, Model model) {

		logger.debug(" 【 Controller 】-【 ExmMajorCtrl 】-【 Edit 】-【 POST 】- 开始运行 ");

		try {

			// ------------------ 获取用户操作的 Menu ------------------
			List<AdmRes> menus = admAcctServ.queryMenuById(Integer.valueOf(curr.getId()));

			// ------------------ Ctrl操作 ------------------
			List<EduMajorRep> array = eduMajorServ.queryListForExam(id);

			model.addAttribute("user", curr);
			model.addAttribute("menus", menus);
			model.addAttribute("htmlTitle", htmlTitle);

			model.addAttribute("id", id);
			model.addAttribute("data", array);

		} catch (Exception e) {
			model.addAttribute("err", e.getMessage());
			return "error/500";
		}

		logger.debug(" 【 Controller 】-【 ExmMajorCtrl 】-【 Edit 】-【 GET 】- 结束运行 ");
		return "exam/major/list";
	}

}
